package region

import (
	"context"
	"fast-boot/app/model"
	"github.com/jinzhu/copier"

	"fast-boot/app/api/admin/internal/svc"
	"fast-boot/app/api/admin/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 获取菜单
func NewGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetLogic {
	return &GetLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetLogic) Get(req *types.SysRegionGetReq) (*types.SysRegionInfo, error) {
	item := model.SysRegionModel{}
	l.svcCtx.GormClient.GormDb.First(&item, req.Id)
	var resp types.SysRegionInfo
	if err := copier.Copy(&resp, item); err != nil {
		return nil, err
	}
	return &resp, nil
}
